#encoding:utf-8

'''
data=2017/1/10 下午3:52
__author__='binpo',
author_email='binpocn@163.com',
'''

'''
如何注册钱包在服务器： 先要按照这个方式进行： suggest_brain_key 这样：
curl -X POST -d '{"method": "suggest_brain_key", "jsonrpc": "2.0", "params": [], "id": 1}' http://127.0.0.1:8089


然后注册钱包
curl -X POST -d '{"method": "register_account", "jsonrpc": "2.0", "params": ["账号","приватный клю密钥匙","приватный ключ秘钥匙","аккаунт","аккаунт账号",0,true], "id": 1}' http://127.0.0.1:8089

'''


'''


 transfer e-chat binpocn163.com 0.001 EDC "have some EDC" true
 res = graphene.transfer("e-chat","binpocn163.com","0.001", "EDC", "have some EDC", True);
'''

'''
programs/cli_wallet/cli_wallet --server-r|
pc-endpoint=wss://114.55.106.139:5921 --rpc-endpoint=127.0.0.1:8089 --chain-id=9|
79b29912e5546dbf47604692aafc94519f486c56221a5705f0c7f5f294df126

'''

'''

screen -S cli
screen -x cli
unlock aa6vuCw84BxQa3uT
'''


'''

  125  2017-01-10 17:04:37 screen -x 13991.cli
  126  2017-01-10 17:07:57 screen -x
  127  2017-01-10 17:08:04 screen -x 14100.server
  128  2017-01-10 17:09:25 programs/cli_wallet/cli_wallet --server-rpc-endpoint=wss://blockchain.e-dinarcoin.com --rpc-endpoint=127.0.0.1:8089 --chain-id=979b29912e5546dbf47604692aafc94519f486c56221a5705f0c7f5f294df126
  129  2017-01-10 17:12:29 programs/cli_wallet/cli_wallet --server-rpc-endpoint=wss://blockchain.e-dinarcoin.com --rpc-endpoint=127.0.0.1:8089 --chain-id=979b29912e5546dbf47604692aafc94519f486c56221a5705f0c7f5f294df126
  130  2017-01-10 17:09:22 screen -x 13991.cli
  131  2017-01-10 17:04:09 programs/witness_node/witness_node --seed-node slave5.edinarcoin.com:5912 --rpc-endpoint=127.0.0.1:5909 --genesis-json=genesis.json
  132  2017-01-10 17:15:20 screen -x 14100.server
  133  2017-01-10 17:16:04 screen -x 13991.cli
  134  2017-01-10 17:16:56 screen -x 14100.server
  135  2017-01-10 17:20:25 programs/cli_wallet/cli_wallet --server-rpc-endpoint=wss://114.55.106.139:5921 --rpc-endpoint=127.0.0.1:8089 --chain-id=979b29912e5546dbf47604692aafc94519f486c56221a5705f0c7f5f294df126
  136  2017-01-10 17:18:50 screen -x 13991.cli
  137  2017-01-10 17:22:30 programs/cli_wallet/cli_wallet --server-rpc-endpoint=wss://114.55.106.139:5921 --rpc-endpoint=127.0.0.1:8089 --chain-id=979b29912e5546dbf47604692aafc94519f486c56221a5705f0c7f5f294df126
  138  2017-01-10 17:23:20 programs/cli_wallet/cli_wallet --server-rpc-endpoint=wss://blockchain.e-dinarcoin.com --rpc-endpoint=127.0.0.1:8089 --chain-id=979b29912e5546dbf47604692aafc94519f486c56221a5705f0c7f5f294df126

programs/witness_node/witness_node --seed-node 114.55.106.139:5908 --rpc-endpoint=127.0.0.1:5909 --genesis-json=genesis.json
programs/cli_wallet/cli_wallet --server-rpc-endpoint=wss://blockchain.e-dinarcoin.com --rpc-endpoint=127.0.0.1:8089 --chain-id=979b29912e5546dbf47604692aafc94519f486c56221a5705f0c7f5f294df126

'''

programs/cli_wallet/cli_wallet --server-rpc-endpoint=ws://114.55.106.139:5921 --rpc-endpoint=127.0.0.1:8089 --chain-id=979b29912e5546dbf47604692aafc94519f486c56221a5705f0c7f5f294df126
programs/witness_node/witness_node --seed-node 114.55.106.139:5908 --rpc-endpoint=127.0.0.1:5909 --genesis-json=genesis.json


programs/witness_node/witness_node --seed-node 114.55.106.139:5908 --rpc-endpoint=127.0.0.1:5909 --genesis-json=genesis.json
programs/cli_wallet/cli_wallet --server-rpc-endpoint=wss://blockchain.e-dinarcoin.com --rpc-endpoint=127.0.0.1:8089 --chain-id=979b29912e5546dbf47604692aafc94519f486c56221a5705f0c7f5f294df126


from grapheneapi.grapheneclient import GrapheneClient
from grapheneapi.grapheneapi import GrapheneAPI
from grapheneexchange.exchange import GrapheneExchange
rpc = GrapheneAPI("127.0.0.1", 8089, "e-chat", "aa6vuCw84BxQa3uT")
class Config():
    wallet_host = "127.0.0.1"
    wallet_port = 8089
    wallet_user = "e-chat"
    wallet_password = "aa6vuCw84BxQa3uT"
    witness_url = "ws://127.0.0.1:5909"
    account = "e-chat"

class Config():
    wallet_host = "127.0.0.1"
    wallet_port = 8089
    wallet_user = "e-chat"
    wallet_password = "aa6vuCw84BxQa3uT"
    account = "e-chat"


class Config():
    wallet_host = "127.0.0.1"
    wallet_port = 8089
    wallet_user = "e-chat"
    wallet_password = "aa6vuCw84BxQa3uT"

    account = "e-chat"


graphene = GrapheneClient(Config)
graphene.rpc.transfer2('e-chat','binpocn163.com','0.001',"EDC","transfer some edc",True)

graphene.rpc.get_account_history("e-chat", 2)


exchange = GrapheneExchange(graphene)
exchange.propose_only=True
exchange.transfer(0.001,'EDC',"5", "USD", "memo", True);

print(graphene.rpc.info())
print(graphene.rpc.get_account(""))
print(graphene.rpc.get_asset("USD"))

class Config(GrapheneWebsocketProtocol):  ## Note the dependency
    wallet_host           = "localhost"
    wallet_port           = 8092
    wallet_user           = "e-chat"
    wallet_password       = ""
    witness_url           = "ws://localhost:8090/"
    witness_user          = ""
    witness_password      = ""



    graphene.rpc.transfer2('e-chat','binpocn163.com',0.001,"have some EDC",True)

from grapheneexchange import GrapheneExchange
import json

class Config():
    wallet_host = "localhost"
    wallet_port = 8089
    wallet_user = "e-chat"
    wallet_password = "aa6vuCw84BxQa3uT"
    witness_url = "ws://127.0.0.1:5909"
    witness_user = "e-chat"
    witness_password = "aa6vuCw84BxQa3uT"
    account = "e-chat"

dex = GrapheneExchange(Config)


dex.transfer(0.001,'EDC','binpocn163.com','Asset to transfer')

propose_transfer('e-chat','e-chat','binpocn@163.com',0.001,'EDC')



class Config():
    wallet_host = "localhost"
    wallet_port = 8089
    witness_url = "ws://127.0.0.1:5909"

'''
 {"name":"connect","api":[["about",3],["add_operation_to_builder_transaction",5],["approve_proposal",98],
 ["begin_builder_transaction",4],["blind_history",118],["blind_transfer",117],
 ["borrow_asset",34],["buy",33],["cancel_order",35],["create_account_with_brain_key",30],
 ["create_asset",41],["create_blind_account",114],["create_committee_member",56],["create_witness",61],
 ["create_worker",63],["dbg_generate_blocks",102],["dbg_make_mia",100],["dbg_make_uia",99],
 ["dbg_push_blocks",101],["dbg_stream_json_objects",103],["dbg_update_object",104],["dump_private_keys",18],
 ["edc_fund_asset_fee_pool",50],["flood_network",105],["fund_asset_fee_pool",49],["get_account",71],
 ["get_account_count",79],["get_account_history",80],["get_account_id",77],["get_account_operation_history",81],
 ["get_accounts_info",74],["get_asset",47],["get_bitasset_data",48],["get_blind_accounts",111],
 ["get_blind_balances",113],["get_block",78],["get_call_orders",90],["get_committee_member",58],
 ["get_dynamic_global_properties",84],["get_global_properties",83],["get_key_label",109],
 ["get_limit_orders",89],["get_market_history",82],["get_my_blind_accounts",112],
 ["get_object",85],["get_order_book",120],["get_private_key",86],["get_prototype_operation",95],
 ["get_public_key",110],["get_referrals",72],["get_referrals_by_id",73],["get_settle_orders",91],
 ["get_transaction_id",40],["get_user_count_by_ranks",75],["get_user_count_with_balances",76],
 ["get_vesting_balances",65],["get_witness",57],["gethelp",1],["global_settle_asset",52],["help",0],
 ["import_account_keys",25],["import_accounts",24],["import_balance",26],["import_key",23],["info",2],
 ["is_locked",14],["is_new",13],["issue_asset",46],["list_account_balances",21],["list_accounts",20],
 ["list_assets",22],["list_committee_members",60],["list_my_accounts",19],["list_witnesses",59],
 ["load_wallet_file",87],["lock",15],["network_add_nodes",106],["network_get_connected_peers",107],
 ["normalize_brain_key",88],["preview_builder_transaction",8],["propose_account_restriction",55],["propose_builder_transaction",10],
 ["propose_builder_transaction2",11],["propose_fee_change",97],["propose_parameter_change",96],
 ["publish_asset_feed",45],["receive_blind_transfer",119],["register_account",28],["remove_builder_transaction",12],
 ["replace_operation_in_builder_transaction",6],["reserve_asset",51],["save_wallet_file",92],["sell",32],["sell_asset",31],
 ["serialize_transaction",93],["set_desired_witness_and_committee_member_count",70],["set_fees_on_builder_transaction",7],
 ["set_key_label",108],["set_password",17],["set_voting_proxy",69],["settle_asset",53],["sign_builder_transaction",9],
 ["sign_transaction",94],["suggest_brain_key",27],["transfer",36],["transfer2",37],["transfer_from_blind",116],
 ["transfer_to_blind",115],["transfer_with_fee_symbol",38],["transfer_with_fee_symbol2",39],["unlock",16],
 ["update_asset",42],["update_asset_feed_producers",44],["update_bitasset",43],["update_witness",62],
 ["update_worker_votes",64],["upgrade_account",29],
 ["vote_for_committee_member",67],["vote_for_witness",68],["whitelist_account",54],["withdraw_vesting",66]]}
'''
#import_key binpocn163.com EDC85A1XUwBc6qSP9hSfHf6uusd3rHBkVfUFmXv8qS4YiaQ1bDE3A


#EDC85A1XUwBc6qSP9hSfHf6uusd3rHBkVfUFmXv8qS4YiaQ1bDE3A

#pub = PublicKey("EDC85A1XUwBc6qSP9hSfHf6uusd3rHBkVfUFmXv8qS4YiaQ1bDE3A", prefix="EDC")

#print(format(pub.address,"BTS"))

graphene.rpc.get_asset('1.3.1')


account = graphene.rpc.get_account("e-chat")
print(graphene.ws.get_account_history(account["id"],"1.11.0",2,"1.11.0",api="history"))
print(graphene.rpc.get_account_history("e-chat", 1,2))

graphene.ws.getFullAccountHistory('e-chat',1,2)

graphene.ws.getAccountHistory("e-chat",begin=1,limit=110,)


ws = GrapheneWebsocketRPC("ws://127.0.0.1:5909","e-chat","aa6vuCw84BxQa3uT")
wc.get_account('e-chat')
ws.getFullAccountHistory('e-chat',1,10)


graphene.rpc.returnOpenOrdersStruct()



#注册账号流程
#step 1
graphene.rpc.suggest_brain_key()
#step 2
graphene.rpc.create_account_with_brain_key("QUITTED SLURBOW RERUB NUTRICE FLATTIE HATBRIM TENREC SMOTTER OMBER UNWEB ODDLY SQUIRTY NASALLY TUMEFY ROBUST TAOYIN",'etao','e-chat','e-chat',True)

graphene.rpc.create_account_with_brain_key("QUITTED SLURBOW RERUB NUTRICE FLATTIE HATBRIM TENREC SMOTTER OMBER UNWEB ODDLY SQUIRTY NASALLY TUMEFY ROBUST TAOYIN",'etao','e-chat','e-chat',True)
#step 3 注册成功
{'extensions': [], 'operations': [[5, {'referrer': '1.2.328095', 'active': {'address_auths': [], 'key_auths': [['EDC7N5UgXmTpj9zrKx82ruFV7NjQ6WVc5B3mRTQkBVhtunkFDSayV', 1]], 'account_auths': [], 'weight_threshold': 1}, 'fee': {'amount': 0, 'asset_id': '1.3.1'}, 'options': {'extensions': [], 'num_committee': 0, 'memo_key': 'EDC5Py2mUmLJ5Nwu6vknHkHratxhGzqGb1ArT1gBXE8EL7XojGDQy', 'num_witness': 0, 'votes': [], 'voting_account': '1.2.5'}, 'registrar': '1.2.328095', 'name': 'etao', 'owner': {'address_auths': [], 'key_auths': [['EDC6qv9rr7Wqygvnd2GgTHLD8p76TCY1Mv3uKzdt4e9b13k8YHkZs', 1]], 'account_auths': [], 'weight_threshold': 1}, 'extensions': {}, 'referrer_percent': 0}]], 'expiration': '2017-01-19T07:18:25', 'ref_block_num': 21833, 'signatures': ['200d204eba4308073e48a4dfa1ee6df49867a0c11b4f8e8c64a0bf3d55e3aad2943fe645dcccebd32d43cf01a82bc630628cb4450d76309576e7681832a1123dab'], 'ref_block_prefix': 4292651823}

graphene.rpc.import_accounts('etao','EDC5Py2mUmLJ5Nwu6vknHkHratxhGzqGb1ArT1gBXE8EL7XojGDQy')
graphene.rpc.import_balance('etao','EDC5Py2mUmLJ5Nwu6vknHkHratxhGzqGb1ArT1gBXE8EL7XojGDQy',True)

graphene.rpc.import_balance('etao','QUITTED SLURBOW RERUB NUTRICE FLATTIE HATBRIM TENREC SMOTTER OMBER UNWEB ODDLY SQUIRTY NASALLY TUMEFY ROBUST TAOYIN',True)
#钱包的所有函数
#https://github.com/cryptonomex/graphene/blob/master/libraries/wallet/include/graphene/wallet/wallet.hpp


screen -S n programs/cli_wallet/cli_wallet --server-rpc-endpoint=ws://114.55.106.139:5921 --rpc-endpoint=127.0.0.1:8089 --chain-id=979b29912e5546dbf47604692aafc94519f486c56221a5705f0c7f5f294df126
